home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / play movie / common files / comframework.c next >
Encoding:
Text File  |  2000-10-06  |  54.0 KB  |  1,982 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.c
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <15>         03/02/00    rtm        made changes to get things running under CarbonLib
  17. //       <14>         02/16/00    rtm        added QTFrame_GetWindowPtrFromWindowReference
  18. //       <13>         01/19/00    rtm        revised QTFrame_IsAppWindow (dialog windows no longer count as application
  19. //                                    windows); added QTFrame_BuildFileTypeList and QTFrame_AddComponentFileTypes
  20. //                                    to avoid calling GetMovieImporterForDataRef in QTFrame_FilterFiles; removed
  21. //                                    the hard-coded file types
  22. //       <12>         01/14/00    rtm        added support for graphics files, using graphics importers
  23. //       <11>         12/28/99    rtm        added QTFrame_ConvertMacToWinRect and QTFrame_ConvertWinToMacRect
  24. //       <10>         12/21/99    rtm        hard-coded some file types into QTFrame_FilterFiles; if we let QuickTime
  25. //                                    to do all the testing (using GetMovieImporterForDataRef), it takes too long
  26. //       <9>         12/17/99    rtm        added some code to QTFrame_SetMenuItemState to work around a problem that
  27. //                                    appears under MacOS 8.5.1 (as far as I can tell...)
  28. //       <8>         12/16/99    rtm        added QTApp_HandleMenu calls to _HandleFileMenuItem and _HandleEditMenuItem
  29. //                                    to allow the application-specific code to intercept menu item selections;
  30. //                                    added QTFrame_FilterFiles
  31. //       <7>         12/15/99    rtm        added QTApp_Idle call to QTFrame_IdleMovieWindows
  32. //       <6>         12/11/99    rtm        added GetMenuState call to Windows portion of QTFrame_SetMenuItemLabel;
  33. //                                    tweaked _SizeWindowToMovie to guard against NULL movie and/or controller
  34. //       <5>         11/30/99    rtm        added QTFrame_CloseMovieWindows
  35. //       <4>         11/27/99    rtm        added QTFrame_GetFileFilterUPP
  36. //       <3>         11/17/99    rtm        finished support for Navigation Services; added QTFrame_IdleMovieWindows
  37. //       <2>         11/16/99    rtm        begun support for Navigation Services
  38. //       <1>         11/05/99    rtm        first file
  39. //
  40. //    This file contains several kinds of functions: (1) functions that use completely cross-platform APIs and
  41. //    which therefore can be compiled and run for both Mac and Windows platforms with no changes whatsoever (a
  42. //    good example of this is QTFrame_SaveAsMovieFile); (2) functions that are substantially the same on both
  43. //    platforms but which require several short platform-dependent #ifdef TARGET_OS_ blocks (a good example of
  44. //    this is QTFrame_AdjustMenus); (3) functions that retrieve data from framework-specific data structures (a
  45. //    good example of this is QTFrame_GetWindowObjectFromWindow); (4) functions that provide a platform-neutral
  46. //    interface to platform-specific operations (a good example of this is QTFrame_Beep). In a nutshell, this
  47. //    file attempts to provide platform-independent services to its callers, typically functions in the files
  48. //    MacFramework.c, WinFramework.c, and ComApplication.c.
  49. //
  50. //    In general, you should not need to modify this file. Your application-specific code should usually be put
  51. //    into the file ComApplication.c.
  52. //
  53. //////////
  54.  
  55. //////////
  56. //
  57. // header files
  58. //
  59. //////////
  60.  
  61.  
  62. #include "ComFramework.h"
  63. #include "PlayMovie.h"
  64. #include "ExportMovie.h"
  65.  
  66.  
  67. //////////
  68. //
  69. // global variables
  70. //
  71. //////////
  72.  
  73. Rect                    gMCResizeBounds;                        // maximum size for any movie window
  74. OSType                     *gValidFileTypes = NULL;                // the list of file types that our application can open
  75.  
  76. #if TARGET_OS_WIN32
  77. extern HWND                ghWnd;
  78. extern HWND                ghWndMDIClient;
  79. extern BOOL                gWeAreSizingWindow;
  80. #endif
  81.  
  82. #if TARGET_OS_MAC
  83. extern Str255            gAppName;
  84. void                    QTFrame_HandleEvent (EventRecord *theEvent);
  85. #endif
  86.  
  87.  
  88. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. //
  90. // Menu-handling functions.
  91. //
  92. // Use these functions to handle items in the File and Edit menus.
  93. //
  94. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  95.  
  96. //////////
  97. //
  98. // QTFrame_HandleFileMenuItem
  99. // Handle the specified File menu item.
  100. //
  101. //////////
  102.  
  103. void QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  104. {
  105.     // give the application-specific code a chance to intercept the menu item selection
  106.     if (QTApp_HandleMenu(theMenuItem))
  107.         return;
  108.         
  109.     switch (theMenuItem) {
  110.     
  111.         case IDM_FILENEW:
  112.             QTFrame_CreateNewMovie();
  113.             break;
  114.  
  115.         case IDM_FILEOPEN:
  116.             OpenMovie();
  117.             //QTFrame_OpenMovieInWindow(NULL, NULL);
  118.             break;
  119.  
  120.         case IDM_FILECLOSE:
  121.             QTFrame_DestroyMovieWindow(theWindow);
  122.             break;
  123.  
  124.         case IDM_FILESAVE:
  125.             QTFrame_UpdateMovieFile(theWindow);
  126.             break;
  127.  
  128.         case IDM_FILESAVEAS:
  129.             QTFrame_SaveAsMovieFile(theWindow);
  130.             break;
  131.             
  132.         case IDM_EXIT:
  133.             QTFrame_QuitFramework();
  134.             break;
  135.  
  136.         default:
  137.             break;
  138.     } // switch (theMenuItem)
  139.     
  140. }
  141.  
  142.  
  143. //////////
  144. //
  145. // QTFrame_HandleEditMenuItem
  146. // Perform the specified edit operation on the specified window.
  147. //
  148. //////////
  149.  
  150. void QTFrame_HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  151. {
  152.     WindowObject        myWindowObject = NULL;
  153.     MovieController     myMC = NULL;
  154.     Movie                 myEditMovie = NULL;                // the movie created by some editing operations
  155.     
  156.     // give the application-specific code a chance to intercept the menu item selection
  157.     if (QTApp_HandleMenu(theMenuItem))
  158.         return;
  159.     
  160.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  161.     myMC = QTFrame_GetMCFromWindow(theWindow);
  162.     
  163.     // make sure we have a valid movie controller and a valid window object
  164.     if ((myMC == NULL) || (myWindowObject == NULL))
  165.         return;
  166.  
  167.     switch (theMenuItem) {
  168.     
  169.         case IDM_EDITUNDO:
  170.             MCUndo(myMC);
  171.             (**myWindowObject).fIsDirty = true;
  172.             break;
  173.  
  174.         case IDM_EDITCUT:
  175.             myEditMovie = MCCut(myMC);
  176.             (**myWindowObject).fIsDirty = true;
  177.             break;
  178.  
  179.         case IDM_EDITCOPY:
  180.             myEditMovie = MCCopy(myMC);
  181.             break;
  182.  
  183.         case IDM_EDITPASTE:
  184.             MCPaste(myMC, NULL);
  185.             (**myWindowObject).fIsDirty = true;
  186.             break;
  187.  
  188.         case IDM_EDITCLEAR:
  189.             MCClear(myMC);
  190.             (**myWindowObject).fIsDirty = true;
  191.             break;
  192.             
  193.         case IDM_EDITSELECTALL:
  194.             QTUtils_SelectAllMovie(myMC);
  195.             break;
  196.  
  197.         case IDM_EDITSELECTNONE:
  198.             QTUtils_SelectNoneMovie(myMC);
  199.             break;
  200.  
  201.         default:
  202.             break;
  203.     } // switch (theMenuItem)
  204.     
  205.     // place any cut or copied movie segment onto the scrap
  206.     if (myEditMovie != NULL) {
  207.         PutMovieOnScrap(myEditMovie, 0L);
  208.         DisposeMovie(myEditMovie);
  209.     }
  210. }
  211.  
  212.  
  213. //////////
  214. //
  215. // QTFrame_AdjustMenus 
  216. // Adjust the application's menus.
  217. //
  218. // On Windows, the theWindow parameter is a handle to the active MDI *child* window, if any.
  219. // On Mac, the theWindow parameter is a pointer to the frontmost window, if any.
  220. //
  221. //////////
  222.  
  223. int QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu)
  224. {
  225. #if TARGET_OS_MAC
  226. #pragma unused(theMenu)
  227. #endif
  228.  
  229.     WindowObject        myWindowObject = NULL; 
  230.     MovieController     myMC = NULL;
  231.     MenuReference        myMenu = NULL;
  232.     
  233. #if TARGET_OS_WIN32
  234.     myMenu = theMenu;
  235. #endif
  236.  
  237.     if (theWindow != NULL)
  238.         myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  239.  
  240.     if (myWindowObject != NULL)
  241.         myMC = (**myWindowObject).fController;
  242.  
  243.     //////////
  244.     //
  245.     // configure the Edit menu
  246.     //
  247.     //////////
  248.     
  249. #if TARGET_OS_MAC
  250.     myMenu = GetMenuHandle(kEditMenuResID);
  251. #endif
  252.     if (myMC != NULL) {
  253.         long    myFlags;
  254.         
  255.         MCGetControllerInfo(myMC, &myFlags);
  256.     
  257.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, myFlags & mcInfoUndoAvailable ? kEnableMenuItem : kDisableMenuItem);
  258.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, myFlags & mcInfoCutAvailable ? kEnableMenuItem : kDisableMenuItem);
  259.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, myFlags & mcInfoCopyAvailable ? kEnableMenuItem : kDisableMenuItem);
  260.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, myFlags & mcInfoPasteAvailable ? kEnableMenuItem : kDisableMenuItem);
  261.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, myFlags & mcInfoClearAvailable ? kEnableMenuItem : kDisableMenuItem);
  262.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  263.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  264.     } else {
  265.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, kDisableMenuItem);
  266.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, kDisableMenuItem);
  267.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, kDisableMenuItem);
  268.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, kDisableMenuItem);
  269.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, kDisableMenuItem);
  270.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, kDisableMenuItem);
  271.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, kDisableMenuItem);
  272.     }
  273.  
  274.     //////////
  275.     //
  276.     // configure the File menu
  277.     //
  278.     //////////
  279.     
  280. #if TARGET_OS_MAC
  281.     myMenu = GetMenuHandle(kFileMenuResID);
  282. #endif
  283.     if (theWindow != NULL) {                // there is a window open
  284.         // handle the Close command
  285.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kEnableMenuItem);
  286.         
  287.         // handle the Save As and Save commands
  288.         if (myWindowObject != NULL) {
  289.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kEnableMenuItem);
  290.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, (**myWindowObject).fIsDirty ? kEnableMenuItem : kDisableMenuItem);
  291.         } else {
  292.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  293.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  294.         }
  295.     
  296.     } else {                                // there is no window open    
  297.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  298.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  299.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem);        
  300.     }
  301.  
  302.     // adjust any application-specific menus
  303.     QTApp_AdjustMenus(theWindow, theMenu);
  304.  
  305.     return(0);
  306. }
  307.  
  308.  
  309. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  310. //
  311. // Movie-handling functions.
  312. //
  313. // Use these functions to create new movies, open existing movies, save movies, and so forth.
  314. //
  315. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  316.  
  317. //////////
  318. //
  319. // QTFrame_CreateNewMovie
  320. // Create a new movie in a window; returns true if successful.
  321. //
  322. // NOTE: There are several user interface issues that are blissfully ignored by this routine,
  323. // principally the preferred names and the on-screen locations of the new windows. 
  324. //
  325. //////////
  326.  
  327. Boolean QTFrame_CreateNewMovie (void)
  328. {
  329.     Movie                myMovie = NULL;
  330.     FSSpec                myFSSpec;
  331.     StringPtr             myName = QTUtils_ConvertCToPascalString(kNewMovieName);
  332.     
  333.     myMovie = NewMovie(newMovieActive);
  334.     if (myMovie == NULL)
  335.         return(false);
  336.     
  337.     // create a default FSSpec
  338.     FSMakeFSSpec(0, 0L, myName, &myFSSpec);
  339.     
  340.     free(myName);
  341.     
  342.     return(QTFrame_OpenMovieInWindow(myMovie, &myFSSpec));
  343. }
  344.  
  345.  
  346. //////////
  347. //
  348. // QTFrame_OpenMovieInWindow
  349. // Open a movie in a new movie window; return true if successful.
  350. //
  351. // This function is called from several places in our framework. The following combinations are possible:
  352. //    * theMovie == NULL, theFSSpec == NULL: no movie, no file; elicit a movie file from user and open it
  353. //    * theMovie != NULL, theFSSpec == NULL: new movie, no file (yet)
  354. //    * theMovie == NULL, theFSSpec != NULL: no movie, but we have an FSSpec; so just open the specified movie file
  355. //    * theMovie != NULL, theFSSpec != NULL: new movie, theFSSpec contains (at least) the movie name
  356. //
  357. //////////
  358.  
  359. Boolean QTFrame_OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec)
  360. {
  361.     WindowObject            myWindowObject = NULL;
  362.     Movie                    myMovie = NULL;
  363.     MovieController            myMC = NULL;
  364.     GraphicsImportComponent    myImporter = NULL;
  365.     WindowReference            myWindow = NULL;
  366.     FSSpec                    myFSSpec;
  367.     short                    myRefNum = kInvalidFileRefNum;
  368.     short                    myResID = 0;
  369.     OSType                     myTypeList[] = {kQTFileTypeMovie, kQTFileTypeQuickTimeImage};
  370.     short                    myNumTypes = 2;
  371.     GrafPtr                    mySavedPort;
  372.     Rect                    myRect = {0, 0, 0, 0};
  373.     Point                    myPoint;
  374.     QTFrameFileFilterUPP    myFileFilterUPP = NULL;
  375.     OSErr                    myErr = noErr;
  376.  
  377. #if TARGET_OS_MAC
  378.     myNumTypes = 0;
  379. #endif
  380.  
  381.     // get the current port; we may need to restore it if we cannot successfully create a new window
  382.     GetPort(&mySavedPort);
  383.     
  384.     // if we got neither a movie nor an FSSpec passed in, prompt the user for a movie file
  385.     if ((theMovie == NULL) && (theFSSpec == NULL)) {
  386.         myFileFilterUPP = QTFrame_GetFileFilterUPP((ProcPtr)QTFrame_FilterFiles);
  387.     
  388.         myErr = QTFrame_GetOneFileWithPreview(myNumTypes, (QTFrameTypeListPtr)myTypeList, &myFSSpec, myFileFilterUPP);
  389.     
  390.         if (myFileFilterUPP != NULL)
  391.             DisposeNavObjectFilterUPP(myFileFilterUPP);
  392.  
  393.         if (myErr != noErr)
  394.             goto bail;
  395.     }
  396.     
  397.     // if we got an FSSpec passed in, copy it into myFSSpec
  398.     if (theFSSpec != NULL) {
  399.         FSMakeFSSpec(theFSSpec->vRefNum, theFSSpec->parID, theFSSpec->name, &myFSSpec);        
  400.     }
  401.  
  402.     // if we got no movie passed in, read one from the specified file
  403.     if (theMovie == NULL) {
  404.  
  405.         // see if the FSSpec picks out an image file; if so, skip the movie-opening code
  406.         // NOTE: The next 3 lines were commented out to get this working on OS X DP3
  407.         myErr = GetGraphicsImporterForFile(&myFSSpec, &myImporter);
  408.         if (myImporter != NULL)
  409.             goto gotImageFile;
  410.             
  411.         // ideally, we'd like read and write permission, but we'll settle for read-only permission
  412.         myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
  413.         if (myErr != noErr)
  414.             myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdPerm);
  415.  
  416.         // if we couldn't open the file with even just read-only permission, bail....
  417.         if (myErr != noErr)
  418.             goto bail;
  419.  
  420.         // now fetch the first movie from the file
  421.         myResID = 0;
  422.         myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);
  423.         if (myErr != noErr)
  424.             goto bail;
  425.     } else {
  426.         myMovie = theMovie;
  427.     }
  428.  
  429.     //////////
  430.     //
  431.     // at this point, myMovie is an open movie, but myFSSpec may or may not be a valid FSSpec
  432.     //
  433.     //////////
  434.     
  435.     // set the default progress procedure for the movie
  436.     SetMovieProgressProc(myMovie, (MovieProgressUPP)-1, 0);
  437.         
  438. gotImageFile:
  439.     // create a new window to display the movie in
  440.     myWindow = QTFrame_CreateMovieWindow();
  441.     if (myWindow == NULL)
  442.         goto bail;
  443.     
  444.     myWindowObject = QTFrame_GetWindowObjectFromWindow(myWindow);
  445.     if (myWindowObject == NULL)
  446.         goto bail;
  447.     
  448.     // set the window title
  449.     QTFrame_SetWindowTitleFromFSSpec(myWindow, &myFSSpec, true);
  450.  
  451.     // make sure the movie or image file uses the window GWorld
  452.     if (myMovie != NULL)
  453.         SetMovieGWorld(myMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  454.  
  455.     if (myImporter != NULL)
  456.         GraphicsImportSetGWorld(myImporter, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  457.  
  458.     // create and configure the movie controller
  459.     myMC = QTFrame_SetupController(myMovie, myWindow, true);
  460.         
  461.     // store movie info in the window record
  462.     (**myWindowObject).fMovie = myMovie;
  463.     (**myWindowObject).fController = myMC;
  464.     (**myWindowObject).fGraphicsImporter = myImporter;
  465.     (**myWindowObject).fFileResID = myResID;
  466.     (**myWindowObject).fFileRefNum = myRefNum;
  467.     (**myWindowObject).fCanResizeWindow = true;
  468.     (**myWindowObject).fIsDirty = false;
  469.     (**myWindowObject).fIsQTVRMovie = QTUtils_IsQTVRMovie(myMovie);
  470.     (**myWindowObject).fInstance = NULL;
  471.     (**myWindowObject).fAppData = NULL;
  472.     (**myWindowObject).fFileFSSpec = myFSSpec;
  473.     
  474.     // do any application-specific window object initialization
  475.     QTApp_SetupWindowObject(myWindowObject);
  476.     
  477.     // size the window to fit the movie and controller
  478.     QTFrame_SizeWindowToMovie(myWindowObject);
  479.  
  480.     // set the movie's play hints to allow dynamic resizing
  481.     SetMoviePlayHints(myMovie, hintsAllowDynamicResize, hintsAllowDynamicResize);
  482.  
  483.     // set the movie's position, if it has a 'WLOC' user data atom
  484.     myErr = QTUtils_GetWindowPositionFromFile(myMovie, &myPoint);
  485.  
  486.     // show the window
  487. #if TARGET_OS_MAC
  488.     MoveWindow(myWindow, myPoint.h, myPoint.v, false);
  489.     ShowWindow(myWindow);
  490.     SelectWindow(myWindow);                                // make it front-most, since it's just been created
  491.     InvalWindowRect(myWindow, GetWindowPortBounds(myWindow, &myRect));
  492. #endif
  493. #if TARGET_OS_WIN32
  494.     SetWindowPos(myWindow, 0, myPoint.h, myPoint.v, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  495.     ShowWindow(myWindow, SW_SHOW);
  496.     UpdateWindow(myWindow);
  497. #endif
  498.  
  499.     // if the movie is a streamed movie, then start it playing immediately
  500.     if (QTUtils_IsStreamedMovie(myMovie))
  501.         MCDoAction(myMC, mcActionPrerollAndPlay, (void *)GetMoviePreferredRate(myMovie));
  502.         
  503.     return(true);
  504.     
  505. bail:
  506.     if (myWindow != NULL)
  507. #if TARGET_OS_MAC
  508.         DisposeWindow(myWindow);
  509. #endif
  510. #if TARGET_OS_WIN32
  511.         SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)myWindow, 0L);
  512. #endif
  513.         
  514.     if (myMC != NULL)
  515.         DisposeMovieController(myMC);
  516.         
  517.     if (myMovie != NULL)
  518.         DisposeMovie(myMovie);
  519.         
  520.     if (myRefNum != 0)
  521.         CloseMovieFile(myRefNum);
  522.  
  523.     if (myImporter != NULL)
  524.         CloseComponent(myImporter);
  525.         
  526.     MacSetPort(mySavedPort);    // restore the port that was active when this function was called
  527.  
  528.     return(false);
  529. }
  530.  
  531.  
  532. //////////
  533. //
  534. // QTFrame_SetupController
  535. // Create and configure the movie controller.
  536. //
  537. //////////
  538.  
  539. MovieController QTFrame_SetupController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow)
  540. {
  541. #if TARGET_OS_WIN32
  542. #pragma unused(theMoveWindow)
  543. #endif
  544.  
  545.     MovieController            myMC = NULL;
  546.     Rect                    myRect;
  547.     WindowObject            myWindowObject = NULL;
  548.     GrafPtr                    mySavedPort;
  549.  
  550.     if ((theMovie == NULL) || (theWindow == NULL))
  551.         return(NULL);
  552.         
  553.     // get our window specific data
  554.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  555.     if (myWindowObject == NULL)
  556.         return(NULL);
  557.         
  558.     GetPort(&mySavedPort);
  559.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  560.     
  561.     // resize the movie bounding rect and offset to 0,0
  562.     GetMovieBox(theMovie, &myRect);
  563.     MacOffsetRect(&myRect, -myRect.left, -myRect.top);
  564.     SetMovieBox(theMovie, &myRect);
  565.     AlignWindow(QTFrame_GetWindowFromWindowReference(theWindow), false, &myRect, NULL);
  566.  
  567.     // create the movie controller
  568.     myMC = NewMovieController(theMovie, &myRect, mcTopLeftMovie);
  569.     if (myMC == NULL)
  570.         return(NULL);
  571.         
  572.     // enable the default movie controller editing
  573.     MCEnableEditing(myMC, true);
  574.         
  575.     // suppress movie badge
  576.     MCDoAction(myMC, mcActionSetUseBadge, (void *)false);
  577.  
  578.     // set the initial looping state of the movie
  579.     QTUtils_SetLoopingStateFromFile(theMovie, myMC);
  580.     
  581.     // install an action filter that does any application-specific movie controller action processing
  582.     MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(QTApp_MCActionFilterProc), (long)myWindowObject);
  583.  
  584.     // add grow box for the movie controller
  585.     if ((**myWindowObject).fCanResizeWindow) {
  586. #if TARGET_OS_WIN32
  587.         RECT                myRect;
  588.  
  589.         GetWindowRect(GetDesktopWindow(), &myRect);
  590.         OffsetRect(&myRect, -myRect.left, -myRect.top);
  591.         QTFrame_ConvertWinToMacRect(&myRect, &gMCResizeBounds);
  592. #endif
  593. #if TARGET_OS_MAC
  594.         GetRegionBounds(GetGrayRgn(), &gMCResizeBounds);
  595. #endif
  596.  
  597.         MCDoAction(myMC, mcActionSetGrowBoxBounds, &gMCResizeBounds);
  598.     }
  599.     
  600. #if TARGET_OS_MAC
  601.     if (theMoveWindow)
  602.         MoveWindow(theWindow, kDefaultWindowX, kDefaultWindowY, false);
  603. #endif
  604.  
  605.     MacSetPort(mySavedPort);
  606.  
  607.     // add any application-specific controller functionality
  608.     QTApp_SetupController(myMC);
  609.         
  610.     return(myMC);
  611. }
  612.  
  613.  
  614. //////////
  615. //
  616. // QTFrame_SaveAsMovieFile
  617. // Save the movie in the specified window under a new name.
  618. //
  619. // Human interface guidelines for "Save As..." dictate that, if the user selects a new file name
  620. // for the current movie, then that new file shall become the active one. This means that we need
  621. // to close the current movie file and open the new one.
  622. //
  623. //////////
  624.  
  625. OSErr QTFrame_SaveAsMovieFile (WindowReference theWindow)
  626. {
  627.     WindowObject        myWindowObject = NULL;
  628.     Movie                 myMovie = NULL;
  629.     FSSpec                myFile;
  630.     Boolean                myIsSelected = false;
  631.     Boolean                myIsReplacing = false;    
  632.     StringPtr             myPrompt = QTUtils_ConvertCToPascalString(kSavePrompt);
  633.     StringPtr             myFileName = QTUtils_ConvertCToPascalString(kSaveMovieFileName);
  634.     OSErr                myErr = paramErr;
  635.     
  636.     // get the window object associated with the specified window
  637.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  638.     if (myWindowObject == NULL)
  639.         goto bail;
  640.         
  641.     myMovie = (**myWindowObject).fMovie;
  642.     if (myMovie == NULL)
  643.         goto bail;
  644.         
  645.     myFile = (**myWindowObject).fFileFSSpec;
  646.         
  647.     SimpleExportMovie( myMovie, &myFile );
  648.     
  649.     //QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing);
  650.     if (myIsSelected) {
  651. /*        Movie            myNewMovie = NULL;
  652.         MovieController    myMC = NULL;
  653.         //long            myFlags;
  654.         short            myRefNum = kInvalidFileRefNum;
  655.         short            myResID = movieInDataForkResID;
  656.         
  657.         //////////
  658.         //
  659.         // we have a valid FSSpec for the new movie file; now we want to create a new movie file,
  660.         // save the movie data into the new file, close the existing movie file, and then swap
  661.         // the window object data
  662.         //
  663.         //////////
  664.         
  665.         // delete any existing file of that name
  666.         if (myIsReplacing) {
  667.             myErr = DeleteMovieFile(&myFile);
  668.             if (myErr != noErr)
  669.                 goto bail;
  670.         }
  671.         
  672.         myFlags = createMovieFileDeleteCurFile | createMovieFileDontOpenFile | createMovieFileDontCreateMovie | createMovieFileDontCreateResFile;
  673.         myErr = CreateMovieFile(&myFile, sigMoviePlayer, smSystemScript, myFlags, NULL, NULL);
  674.         if (myErr != noErr)
  675.             goto bail;
  676.         
  677.         myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  678.         if (myErr != noErr)
  679.             goto bail;
  680.             
  681.         // write existing movie's data into new movie file
  682.         myErr = AddMovieResource(myMovie, myRefNum, &myResID, myFile.name);
  683.         if (myErr != noErr)
  684.             goto bail;
  685.             
  686.                 myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  687.         if (myErr != noErr)
  688.             goto bail;
  689.  
  690.         // get the new movie from the file
  691.         myErr = NewMovieFromFile(&myNewMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);        
  692.         if (myErr != noErr)
  693.             goto bail;
  694.         
  695.         // create a new movie controller
  696.         myMC = QTFrame_SetupController(myNewMovie, theWindow, false);
  697.         
  698.         //////////
  699.         //
  700.         // if we got to here, we've successfully created a new movie file, and NewMovieFromFile has
  701.         // returned the new movie to us; so we need to close down the current movie and install the
  702.         // new movie in its place
  703.         //
  704.         //////////
  705.         
  706.         // close the existing movie file
  707.         if ((**myWindowObject).fFileRefNum != kInvalidFileRefNum)
  708.             CloseMovieFile((**myWindowObject).fFileRefNum);
  709.         
  710.         // dispose of the existing movie controller and movie resource
  711.         DisposeMovieController((**myWindowObject).fController);
  712.         DisposeMovie(myMovie);
  713.         
  714.         // keep track of the new info
  715.         (**myWindowObject).fMovie = myNewMovie;
  716.         (**myWindowObject).fController = myMC;
  717.         (**myWindowObject).fFileFSSpec = myFile;
  718.         (**myWindowObject).fFileResID = myResID;
  719.         (**myWindowObject).fFileRefNum = myRefNum;
  720.         (**myWindowObject).fIsDirty = false;
  721.  
  722.         // make sure the movie uses the window GWorld in all situations
  723.         SetMovieGWorld(myNewMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference((**myWindowObject).fWindow), NULL);
  724.  
  725.         // set the window title
  726.         QTFrame_SetWindowTitleFromFSSpec(theWindow, &myFile, true);
  727.         */
  728.     } else {
  729.         myErr = userCanceledErr;
  730.     }
  731.     
  732. bail:
  733.     free(myPrompt);
  734.     free(myFileName);
  735.     
  736.     return(myErr);
  737. }
  738.  
  739.  
  740. //////////
  741. //
  742. // QTFrame_UpdateMovieFile
  743. // Update the file (if any) attached to the movie.
  744. //
  745. //////////
  746.  
  747. Boolean QTFrame_UpdateMovieFile (WindowReference theWindow)
  748. {
  749.     WindowObject        myWindowObject = NULL;
  750.     Movie                 myMovie = NULL;
  751.     OSErr                myErr = noErr;
  752.     
  753.     // get the window object associated with the specified window
  754.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  755.     if (myWindowObject == NULL)
  756.         return(false);
  757.         
  758.     myMovie = (**myWindowObject).fMovie;
  759.     if (myMovie == NULL)
  760.         return(false);
  761.     
  762.     // update the current volume setting
  763.     QTUtils_UpdateMovieVolumeSetting(myMovie);
  764.     
  765.     if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)        // brand new movie, so no file attached to it
  766.         myErr = QTFrame_SaveAsMovieFile(theWindow);
  767.     else                                                            // we have an existing file; just update the movie resource
  768.         myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
  769.     
  770.     (**myWindowObject).fIsDirty = false;
  771.  
  772.     return(myErr == noErr);
  773. }
  774.  
  775.  
  776. //////////
  777. //
  778. // QTFrame_IdleMovieWindows
  779. // Do idle-time processing on all open movie windows.
  780. //
  781. //////////
  782.  
  783. void QTFrame_IdleMovieWindows (void)
  784. {    
  785.     WindowReference            myWindow = NULL;
  786.     MovieController            myMC = NULL;
  787.     
  788.     myWindow = QTFrame_GetFrontMovieWindow();
  789.     while (myWindow != NULL) {
  790.         myMC = QTFrame_GetMCFromWindow(myWindow);
  791.         if (myMC != NULL)
  792.             MCIdle(myMC);
  793.             
  794.         QTApp_Idle(myWindow);
  795.         
  796.         myWindow = QTFrame_GetNextMovieWindow(myWindow);
  797.     }
  798. }
  799.  
  800.  
  801. //////////
  802. //
  803. // QTFrame_CloseMovieWindows
  804. // Close all open movie windows.
  805. //
  806. //////////
  807.  
  808. void QTFrame_CloseMovieWindows (void)
  809. {
  810. #if TARGET_OS_MAC    
  811.     WindowReference            myWindow = NULL;
  812.     WindowReference            myNextWindow = NULL;
  813.  
  814.     myWindow = QTFrame_GetFrontMovieWindow();
  815.     while (myWindow != NULL) {
  816.         myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
  817.         QTFrame_DestroyMovieWindow(myWindow);
  818.         myWindow = myNextWindow;
  819.     }
  820. #endif
  821. #if TARGET_OS_WIN32
  822.     SendMessage(ghWnd, WM_COMMAND, (WPARAM)IDM_WINDOWCLOSEALL, 0L);
  823. #endif
  824. }
  825.  
  826.  
  827. //////////
  828. //
  829. // QTFrame_CreateWindowObject
  830. // Create a new window object associated with the specified window.
  831. //
  832. //////////
  833.  
  834. void QTFrame_CreateWindowObject (WindowReference theWindow)
  835. {
  836.     WindowObject            myWindowObject = NULL;
  837.  
  838.     if (theWindow == NULL)
  839.         return;
  840.         
  841.     // allocate space for a window object record and fill in some of its fields
  842.     myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
  843.     if (myWindowObject != NULL) {
  844.         (**myWindowObject).fWindow = theWindow;
  845.         (**myWindowObject).fController = NULL;
  846.         (**myWindowObject).fObjectType = kApplicationSignature;
  847.         (**myWindowObject).fCanResizeWindow = true;
  848.         (**myWindowObject).fInstance = NULL;
  849.         (**myWindowObject).fIsDirty = false;
  850.         (**myWindowObject).fAppData = NULL;
  851.     }
  852.     
  853.     // associate myWindowObject (which may be NULL) with the window
  854. #if TARGET_OS_MAC
  855.     SetWRefCon(theWindow, (long)myWindowObject);
  856. #endif
  857. #if TARGET_OS_WIN32
  858.     SetWindowLong(theWindow, GWL_USERDATA, (LPARAM)myWindowObject);
  859.     
  860.     // associate a GrafPort with this window 
  861.     CreatePortAssociation(theWindow, NULL, 0L);
  862. #endif
  863.     
  864.     // set the current port to the new window
  865.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  866. }
  867.  
  868.  
  869. //////////
  870. //
  871. // QTFrame_CloseWindowObject
  872. // Close a window object and any associated data.
  873. //
  874. //////////
  875.  
  876. void QTFrame_CloseWindowObject (WindowObject theWindowObject)
  877. {
  878.     if (theWindowObject == NULL)
  879.         return;
  880.         
  881.     // close the movie file
  882.     if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
  883.         CloseMovieFile((**theWindowObject).fFileRefNum);
  884.         (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
  885.     }
  886.     
  887.     // dispose movie controller and movie 
  888.     if ((**theWindowObject).fController != NULL) {
  889.         MCSetActionFilterWithRefCon((**theWindowObject).fController, NULL, 0L);
  890.         DisposeMovieController((**theWindowObject).fController);
  891.         (**theWindowObject).fController = NULL;
  892.     }
  893.     
  894.     if ((**theWindowObject).fMovie != NULL) {
  895.         DisposeMovie((**theWindowObject).fMovie);
  896.         (**theWindowObject).fMovie = NULL;
  897.     }
  898.     
  899.     // close the graphics importer, if any
  900.     if ((**theWindowObject).fGraphicsImporter != NULL) {
  901.         CloseComponent((**theWindowObject).fGraphicsImporter);
  902.         (**theWindowObject).fGraphicsImporter = NULL;
  903.     }
  904.     
  905.     // do any application-specific window clean-up
  906.     QTApp_RemoveWindowObject(theWindowObject);
  907.     
  908.     DisposeHandle((Handle)theWindowObject);
  909. }
  910.  
  911.  
  912. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  913. //
  914. // Window-walking utilities.
  915. //
  916. // Use these functions to iterate through all windows or movie windows belonging to the application.
  917. //
  918. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  919.  
  920. //////////
  921. //
  922. // QTFrame_GetFrontAppWindow
  923. // Return a reference to the frontmost application window (whether or not it's a movie window).
  924. //
  925. //////////
  926.  
  927. WindowReference QTFrame_GetFrontAppWindow (void)
  928. {
  929. #if TARGET_OS_MAC
  930.     return(FrontWindow());
  931. #endif
  932. #if TARGET_OS_WIN32
  933.     return(GetWindow(ghWnd, GW_HWNDFIRST));
  934. #endif
  935. }
  936.  
  937.  
  938. //////////
  939. //
  940. // QTFrame_GetNextAppWindow
  941. // Return a reference to the next application window (whether or not it's a movie window).
  942. //
  943. //////////
  944.  
  945. WindowReference QTFrame_GetNextAppWindow (WindowReference theWindow)
  946. {
  947. #if TARGET_OS_MAC
  948.     return(theWindow == NULL ? NULL : GetNextWindow(theWindow));
  949. #endif
  950. #if TARGET_OS_WIN32
  951.     return(GetWindow(theWindow, GW_HWNDNEXT));
  952. #endif
  953. }
  954.  
  955.  
  956. //////////
  957. //
  958. // QTFrame_GetFrontMovieWindow
  959. // Return a reference to the frontmost movie window.
  960. //
  961. //////////
  962.  
  963. WindowReference QTFrame_GetFrontMovieWindow (void)
  964. {
  965.     WindowReference            myWindow;
  966.  
  967. #if TARGET_OS_MAC
  968.     myWindow = QTFrame_GetFrontAppWindow();
  969.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  970.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  971. #endif
  972.  
  973. #if TARGET_OS_WIN32
  974.     myWindow = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  975. #endif
  976.  
  977.     return(myWindow);
  978. }
  979.  
  980.  
  981. //////////
  982. //
  983. // QTFrame_GetNextMovieWindow
  984. // Return a reference to the next movie window.
  985. //
  986. //////////
  987.  
  988. WindowReference QTFrame_GetNextMovieWindow (WindowReference theWindow)
  989. {
  990.     WindowReference            myWindow;
  991.  
  992. #if TARGET_OS_MAC
  993.     myWindow = QTFrame_GetNextAppWindow(theWindow);
  994.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  995.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  996. #endif
  997.  
  998. #if TARGET_OS_WIN32
  999.     myWindow = GetWindow(theWindow, GW_HWNDNEXT);
  1000. #endif
  1001.  
  1002.     return(myWindow);
  1003. }
  1004.  
  1005.  
  1006. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1007. //
  1008. // Data-retrieval utilities.
  1009. //
  1010. // Use the following functions to retrieve the window object, the application-specific data, or the movie
  1011. // controller that is associated with a window.
  1012. //
  1013. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1014.  
  1015. //////////
  1016. //
  1017. // QTFrame_GetWindowObjectFromFrontWindow
  1018. // Get the window object (if any) associated with the front window.
  1019. //
  1020. //////////
  1021.  
  1022. WindowObject QTFrame_GetWindowObjectFromFrontWindow (void)
  1023. {
  1024.     return(QTFrame_GetWindowObjectFromWindow(QTFrame_GetFrontMovieWindow()));
  1025. }
  1026.  
  1027.  
  1028. //////////
  1029. //
  1030. // QTFrame_GetWindowObjectFromWindow
  1031. // Get the window object (if any) associated with the specified window.
  1032. //
  1033. //////////
  1034.  
  1035. WindowObject QTFrame_GetWindowObjectFromWindow (WindowReference theWindow)
  1036. {
  1037.     WindowObject        myWindowObject = NULL;
  1038.  
  1039.     if (!QTFrame_IsAppWindow(theWindow))
  1040.         return(NULL);
  1041.             
  1042. #if TARGET_OS_MAC
  1043.     myWindowObject = (WindowObject)GetWRefCon(theWindow);
  1044. #endif
  1045. #if TARGET_OS_WIN32
  1046.     myWindowObject = (WindowObject)GetWindowLong(theWindow, GWL_USERDATA);
  1047. #endif
  1048.  
  1049.     // make sure this is a window object
  1050.     if (!QTFrame_IsWindowObjectOurs(myWindowObject))
  1051.         return(NULL);
  1052.         
  1053.     return(myWindowObject);
  1054. }
  1055.  
  1056.  
  1057. //////////
  1058. //
  1059. // QTFrame_GetMCFromFrontWindow
  1060. // Get the movie controller (if any) associated with the front window.
  1061. //
  1062. //////////
  1063.  
  1064. MovieController QTFrame_GetMCFromFrontWindow (void)
  1065. {
  1066.     return(QTFrame_GetMCFromWindow(QTFrame_GetFrontMovieWindow()));
  1067. }
  1068.  
  1069.  
  1070. //////////
  1071. //
  1072. // QTFrame_GetMCFromWindow
  1073. // Get the movie controller (if any) associated with the specified window.
  1074. //
  1075. //////////
  1076.  
  1077. MovieController QTFrame_GetMCFromWindow (WindowReference theWindow)
  1078. {
  1079.     MovieController     myMC = NULL;
  1080.     WindowObject        myWindowObject = NULL;
  1081.         
  1082.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1083.     if (myWindowObject != NULL)
  1084.         myMC = (**myWindowObject).fController;
  1085.         
  1086.     return(myMC);
  1087. }
  1088.  
  1089.  
  1090. //////////
  1091. //
  1092. // QTFrame_GetQTVRInstanceFromFrontWindow
  1093. // Get the QTVRInstance (if any) associated with the front window.
  1094. //
  1095. //////////
  1096.  
  1097. QTVRInstance QTFrame_GetQTVRInstanceFromFrontWindow (void)
  1098. {
  1099.     return(QTFrame_GetQTVRInstanceFromWindow(QTFrame_GetFrontMovieWindow()));
  1100. }
  1101.  
  1102.  
  1103. //////////
  1104. //
  1105. // QTFrame_GetQTVRInstanceFromWindow
  1106. // Get the QTVRInstance (if any) associated with the specified window.
  1107. //
  1108. //////////
  1109.  
  1110. QTVRInstance QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow)
  1111. {
  1112.     QTVRInstance         myInstance = NULL;
  1113.     WindowObject        myWindowObject = NULL;
  1114.     
  1115.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1116.     if (myWindowObject != NULL)
  1117.         myInstance = (**myWindowObject).fInstance;
  1118.         
  1119.     return(myInstance);
  1120. }
  1121.  
  1122.  
  1123. //////////
  1124. //
  1125. // QTFrame_GetAppDataFromFrontWindow
  1126. // Get the application-specific data associated with the front window.
  1127. //
  1128. //////////
  1129.  
  1130. Handle QTFrame_GetAppDataFromFrontWindow (void)
  1131. {
  1132.     return(QTFrame_GetAppDataFromWindow(QTFrame_GetFrontMovieWindow()));
  1133. }
  1134.  
  1135.  
  1136. //////////
  1137. //
  1138. // QTFrame_GetAppDataFromWindow
  1139. // Get the application-specific data associated with the specified window.
  1140. //
  1141. //////////
  1142.  
  1143. Handle QTFrame_GetAppDataFromWindow (WindowReference theWindow)
  1144. {
  1145.     WindowObject        myWindowObject = NULL;
  1146.     
  1147.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1148.     if (myWindowObject == NULL)
  1149.         return(NULL);
  1150.         
  1151.     return(QTFrame_GetAppDataFromWindowObject(myWindowObject));
  1152. }
  1153.  
  1154.  
  1155. //////////
  1156. //
  1157. // QTFrame_GetAppDataFromWindowObject
  1158. // Get the application-specific data associated with the specified window object.
  1159. //
  1160. //////////
  1161.  
  1162. Handle QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject)
  1163. {
  1164.     // make sure this is a window object belonging to our application
  1165.     if (!QTFrame_IsWindowObjectOurs(theWindowObject))
  1166.         return(NULL);
  1167.     
  1168.     return((**theWindowObject).fAppData);
  1169. }
  1170.  
  1171.  
  1172. //////////
  1173. //
  1174. // QTFrame_IsWindowObjectOurs
  1175. // Does the specified window object belong to our application?
  1176. //
  1177. //////////
  1178.  
  1179. Boolean QTFrame_IsWindowObjectOurs (WindowObject theWindowObject)
  1180. {
  1181.     OSType        myType = 0L;
  1182.  
  1183.     if ((theWindowObject == NULL) || (*theWindowObject == NULL))
  1184.         return(false);
  1185.         
  1186.     myType = (**theWindowObject).fObjectType;
  1187.     return(myType == kApplicationSignature);
  1188. }
  1189.  
  1190.  
  1191. //////////
  1192. //
  1193. // QTFrame_IsAppWindow
  1194. // Does the specified window belong to our application?
  1195. //
  1196. //////////
  1197.  
  1198. Boolean QTFrame_IsAppWindow (WindowReference theWindow)
  1199. {
  1200.     if (theWindow == NULL)
  1201.         return(false);
  1202.  
  1203. #if TARGET_OS_MAC
  1204.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1205. #endif
  1206. #if TARGET_OS_WIN32
  1207.     return(true);
  1208. #endif
  1209. }
  1210.  
  1211.  
  1212. //////////
  1213. //
  1214. // QTFrame_IsDocWindow
  1215. // Is the specified window a document window (having a WindowObject refcon)?
  1216. //
  1217. //////////
  1218.  
  1219. Boolean QTFrame_IsDocWindow (WindowReference theWindow)
  1220. {
  1221.     if (theWindow == NULL)
  1222.         return(false);
  1223.  
  1224. #if TARGET_OS_MAC
  1225.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1226. #endif
  1227. #if TARGET_OS_WIN32
  1228.     return(true);
  1229. #endif
  1230. }
  1231.  
  1232.  
  1233. //////////
  1234. //
  1235. // QTFrame_ActivateController
  1236. // Activate or deactivate the movie controller in the specified window.
  1237. //
  1238. //////////
  1239.  
  1240. void QTFrame_ActivateController (WindowReference theWindow, Boolean IsActive)
  1241. {
  1242.     WindowObject         myWindowObject = NULL;
  1243.     MovieController        myMC = NULL;
  1244.     Movie                myMovie = NULL;
  1245.     GrafPtr                mySavedPort = NULL;
  1246.     
  1247.     if (theWindow == NULL)
  1248.         return;
  1249.     
  1250.     GetPort(&mySavedPort);
  1251.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  1252.     
  1253.     // get the window object associated with the specified window
  1254.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1255.     if (myWindowObject != NULL) {
  1256.         myMC = (**myWindowObject).fController;
  1257.         myMovie = (**myWindowObject).fMovie;
  1258.         if (myMC != NULL) {
  1259.             MCActivate(myMC, QTFrame_GetWindowFromWindowReference(theWindow), IsActive);
  1260.         } else {
  1261.             if (myMovie != NULL && IsActive) {
  1262.                 UpdateMovie(myMovie);
  1263.                 MoviesTask(myMovie, DoTheRightThing);
  1264.             }
  1265.         }
  1266.     }
  1267.     
  1268.     MacSetPort(mySavedPort);
  1269. }
  1270.  
  1271.  
  1272. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1273. //
  1274. // Miscellaneous utilities.
  1275. //
  1276. // Use the following functions to play beeps, manipulate menus, and do other miscellaneous things.
  1277. //
  1278. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1279.  
  1280. //////////
  1281. //
  1282. // QTFrame_Beep
  1283. // Beep.
  1284. //
  1285. //////////
  1286.  
  1287. void QTFrame_Beep (void)
  1288. {
  1289. #if TARGET_OS_MAC
  1290.     SysBeep(30);
  1291. #endif
  1292. #if TARGET_OS_WIN32
  1293.     MessageBeep(MB_OK);
  1294. #endif
  1295. }
  1296.  
  1297.  
  1298. //////////
  1299. //
  1300. // QTFrame_SetMenuState
  1301. // Set the enabled/disabled state of a menu.
  1302. //
  1303. // On Windows, the theMenuItem parameter must be the (0-based) index in the menu bar of the
  1304. // desired pull-down menu.
  1305. //
  1306. //////////
  1307.  
  1308. void QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1309. {
  1310. #if TARGET_OS_MAC
  1311. #pragma unused(theMenuItem)
  1312.     QTFrame_SetMenuItemState(theMenu, 0, theState);        // menu item == 0 means the entire menu
  1313. #endif
  1314. #if TARGET_OS_WIN32
  1315.     QTFrame_SetMenuItemState(theMenu, theMenuItem, theState | MF_BYPOSITION);
  1316. #endif
  1317. }
  1318.  
  1319.  
  1320. //////////
  1321. //
  1322. // QTFrame_SetMenuItemState
  1323. // Set the enabled/disabled state of a menu item.
  1324. //
  1325. // When running under MacOS 8.5.1, EnableMenuItem and DisableMenuItem seem to do nasty things
  1326. // to the keyboard equivalents associated with a menu; so we'll work around that problem here.
  1327. //
  1328. //////////
  1329.  
  1330. void QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1331. {
  1332. #if TARGET_OS_MAC
  1333.     UInt8        myModifiers;
  1334.     
  1335.     // get the existing menu item modifiers
  1336.     GetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), &myModifiers);
  1337.     
  1338.     if (theState == kEnableMenuItem)
  1339.         EnableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1340.     else
  1341.         DisableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1342.         
  1343.     // restore the previous menu item modifiers
  1344.     SetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), myModifiers);
  1345. #endif
  1346. #if TARGET_OS_WIN32
  1347.     EnableMenuItem(theMenu, (UINT)theMenuItem, (UINT)theState);
  1348. #endif
  1349. }
  1350.  
  1351.  
  1352. //////////
  1353. //
  1354. // QTFrame_SetMenuItemLabel
  1355. // Set the label (that is, the text) of a menu item.
  1356. //
  1357. //////////
  1358.  
  1359. void QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText)
  1360. {
  1361. #if TARGET_OS_MAC
  1362.     Str255        myString;
  1363.     short        mySIndex, myTIndex;
  1364.  
  1365.     // we need to remove the '&' character while converting to a Pascal string    
  1366.     mySIndex = 1;
  1367.     for (myTIndex = 0; myTIndex < strlen(theText); myTIndex++) {
  1368.         if (theText[myTIndex] != '&') {
  1369.             myString[mySIndex] = theText[myTIndex];
  1370.             mySIndex++;
  1371.         }
  1372.     }
  1373.     
  1374.     myString[0] = mySIndex - 1;
  1375.     
  1376.     SetMenuItemText(theMenu, MENU_ITEM(theMenuItem), myString);
  1377. #endif
  1378. #if TARGET_OS_WIN32
  1379.     UINT        myState;
  1380.     
  1381.     // make sure that we preserve the current menu state
  1382.     myState = GetMenuState(theMenu, (UINT)theMenuItem, MF_BYCOMMAND);
  1383.     ModifyMenu(theMenu, (UINT)theMenuItem, MF_BYCOMMAND | MF_STRING | myState, (UINT)theMenuItem, (LPSTR)theText);
  1384. #endif
  1385. }
  1386.  
  1387.  
  1388. //////////
  1389. //
  1390. // QTFrame_SetMenuItemCheck
  1391. // Set the check mark state state of a menu item.
  1392. //
  1393. //////////
  1394.  
  1395. void QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState)
  1396. {
  1397. #if TARGET_OS_MAC
  1398.     MacCheckMenuItem(theMenu, MENU_ITEM(theMenuItem), theState);
  1399. #endif
  1400. #if TARGET_OS_WIN32
  1401.     CheckMenuItem(theMenu, (UINT)theMenuItem, theState ? MF_CHECKED : MF_UNCHECKED);
  1402. #endif
  1403. }
  1404.  
  1405.  
  1406. //////////
  1407. //
  1408. // QTFrame_GetPortFromWindowReference 
  1409. // Return the graphics port associated with a window reference.
  1410. //
  1411. //////////
  1412.  
  1413. GrafPtr QTFrame_GetPortFromWindowReference (WindowReference theWindow)
  1414. {
  1415. #if TARGET_OS_MAC
  1416.     return((GrafPtr)GetWindowPort(theWindow));
  1417. #endif
  1418. #if TARGET_OS_WIN32
  1419.     return(GetNativeWindowPort(theWindow));
  1420. #endif
  1421. }
  1422.  
  1423.  
  1424. //////////
  1425. //
  1426. // QTFrame_GetWindowReferenceFromPort
  1427. // Return the window reference associated with a graphics port.
  1428. //
  1429. //////////
  1430.  
  1431. WindowReference QTFrame_GetWindowReferenceFromPort (GrafPtr thePort)
  1432. {
  1433. #if TARGET_OS_MAC
  1434.     return((WindowReference)GetWindowFromPort((CGrafPtr)thePort));
  1435. #endif
  1436. #if TARGET_OS_WIN32
  1437.     return((WindowReference)GetPortNativeWindow(thePort));
  1438. #endif
  1439. }
  1440.  
  1441.  
  1442. //////////
  1443. //
  1444. // QTFrame_GetWindowFromWindowReference
  1445. // Return the Macintosh window associated with a window reference.
  1446. //
  1447. //////////
  1448.  
  1449. WindowPtr QTFrame_GetWindowFromWindowReference (WindowReference theWindow)
  1450. {
  1451. #if TARGET_OS_MAC
  1452.     return((WindowPtr)theWindow);
  1453. #endif
  1454. #if TARGET_OS_WIN32
  1455.     return((WindowPtr)GetNativeWindowPort(theWindow));
  1456. #endif
  1457. }
  1458.  
  1459.  
  1460. /////////
  1461. //
  1462. // QTFrame_GetWindowWidth
  1463. // Return the width of the specified window.
  1464. //
  1465. //////////
  1466.  
  1467. short QTFrame_GetWindowWidth (WindowReference theWindow)
  1468. {
  1469. #if TARGET_OS_MAC
  1470.     Rect        myRect = {0, 0, 0, 0};
  1471.  
  1472.     if (theWindow != NULL)
  1473.         GetWindowPortBounds(theWindow, &myRect);
  1474. #endif
  1475. #if TARGET_OS_WIN32
  1476.     RECT        myRect = {0L, 0L, 0L, 0L};
  1477.  
  1478.     if (theWindow != NULL)
  1479.         GetWindowRect(theWindow, &myRect);
  1480. #endif
  1481.  
  1482.     return((short)(myRect.right - myRect.left));
  1483. }
  1484.  
  1485.  
  1486. //////////
  1487. //
  1488. // QTFrame_SetWindowTitleFromFSSpec
  1489. // Set the title of the specified window, using the name contained in the specified FSSpec.
  1490. //
  1491. //////////
  1492.  
  1493. void QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs)
  1494. {
  1495. #if TARGET_OS_MAC
  1496. #pragma unused(theAddToRecentDocs)
  1497.     SetWTitle(theWindow, theFSSpecPtr->name);
  1498. #endif
  1499. #if TARGET_OS_WIN32
  1500.     char    *myTempName;
  1501.     char    myWindName[MAX_PATH];
  1502.  
  1503.     // get the full pathname contained in the FSSpec (which is a Str255)
  1504.     myTempName = QTUtils_ConvertPascalToCString(theFSSpecPtr->name);
  1505.  
  1506.     // get the movie file name from the full pathname
  1507.     QTFrame_GetDisplayName(myTempName, myWindName);
  1508.  
  1509.     // set the window title
  1510.     SetWindowText(theWindow, myWindName);
  1511.     
  1512.     // add this document to the Documents list, if so instructed
  1513.     if (theAddToRecentDocs)
  1514.         SHAddToRecentDocs(SHARD_PATH, myTempName);
  1515.     
  1516.     free(myTempName);
  1517. #endif
  1518. }
  1519.  
  1520.  
  1521. //////////
  1522. //
  1523. // QTFrame_SizeWindowToMovie
  1524. // Set the window size to exactly fit the movie and controller (if visible).
  1525. //
  1526. //////////
  1527.  
  1528. void QTFrame_SizeWindowToMovie (WindowObject theWindowObject)
  1529. {
  1530.     Rect                    myMovieBounds;
  1531.     Movie                    myMovie = NULL;
  1532.     MovieController            myMC = NULL;
  1533.     GraphicsImportComponent    myImporter = NULL;
  1534.  
  1535. #if TARGET_OS_WIN32
  1536.     gWeAreSizingWindow = true;
  1537. #endif
  1538.  
  1539.     if (theWindowObject == NULL)
  1540.         goto bail;
  1541.     
  1542.     myMovie = (**theWindowObject).fMovie;
  1543.     myMC = (**theWindowObject).fController;
  1544.     myImporter = (**theWindowObject).fGraphicsImporter;
  1545.  
  1546.     if (myImporter != NULL) {
  1547.         GraphicsImportGetBoundsRect(myImporter, &myMovieBounds);
  1548.         goto gotBounds;
  1549.     }
  1550.  
  1551.     if (myMovie == NULL)
  1552.         return;
  1553.  
  1554.     GetMovieBox(myMovie, &myMovieBounds);
  1555.  
  1556.     if (myMC != NULL)
  1557.         if (MCGetVisible(myMC))
  1558.             MCGetControllerBoundsRect(myMC, &myMovieBounds);
  1559.     
  1560.     // make sure that the movie has a non-zero width;
  1561.     // a zero height is okay (for example, with a music movie with no controller bar)
  1562.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  1563.         myMovieBounds.left = 0;
  1564.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  1565.     }
  1566.  
  1567. gotBounds:    
  1568.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  1569.                                             myMovieBounds.right - myMovieBounds.left,
  1570.                                             myMovieBounds.bottom - myMovieBounds.top,
  1571.                                             true);
  1572.  
  1573. bail:                                        
  1574. #if TARGET_OS_WIN32
  1575.     gWeAreSizingWindow = false;
  1576. #endif
  1577.  
  1578.     return;
  1579. }
  1580.  
  1581.  
  1582. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1583. //
  1584. // File-opening and -saving utilities.
  1585. //
  1586. // The functions are meant to provide replacements for StandardGetFilePreview and StandardPutFile, which
  1587. // are not supported under Carbon. However, Navigation Services is not (yet, at any rate) supported under
  1588. // Windows, so we still need to call through to the Standard File Package.
  1589. //
  1590. // The Navigation Services portion of this code is based selectively on the file NavigationServicesSupport.c
  1591. // by Yan Arrouye and on the developer documentation "Programming With Navigation Services 1.1". The code that
  1592. // determines which files can be opened by QuickTime is based on code by Sam Bushell in CarbonMovieEditor.c.
  1593. //
  1594. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1595.  
  1596. //////////
  1597. //
  1598. // QTFrame_PutFile
  1599. // Save a file under the specified name. Return Boolean values indicating whether the user selected a file
  1600. // and whether the selected file is replacing an existing file.
  1601. //
  1602. //////////
  1603.  
  1604. OSErr QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing)
  1605. {
  1606. #if TARGET_OS_WIN32
  1607.     StandardFileReply    myReply;
  1608. #endif
  1609. #if TARGET_OS_MAC
  1610.     NavReplyRecord        myReply;
  1611.     NavDialogOptions    myDialogOptions;
  1612.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1613. #endif
  1614.     OSErr                myErr = noErr;
  1615.  
  1616.     if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL))
  1617.         return(paramErr);
  1618.     
  1619.     // deactivate any frontmost movie window
  1620.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1621.  
  1622.     // assume we are not replacing an existing file
  1623.     *theIsReplacing = false;
  1624.     
  1625. #if TARGET_OS_WIN32
  1626.     StandardPutFile(thePrompt, theFileName, &myReply);
  1627.     *theFSSpecPtr = myReply.sfFile;
  1628.     *theIsSelected = myReply.sfGood;
  1629.     if (myReply.sfGood)
  1630.         *theIsReplacing = myReply.sfReplacing;
  1631. #endif
  1632.  
  1633. #if TARGET_OS_MAC
  1634.     // specify the options for the dialog box
  1635.     NavGetDefaultDialogOptions(&myDialogOptions);
  1636.     myDialogOptions.dialogOptionFlags += kNavNoTypePopup;
  1637.     myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate;
  1638.     BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1);
  1639.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1640.     BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1);
  1641.     
  1642.     // prompt the user for a file
  1643.     myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL);
  1644.     if ((myErr == noErr) && myReply.validRecord) {
  1645.         AEKeyword        myKeyword;
  1646.         DescType        myActualType;
  1647.         Size            myActualSize = 0;
  1648.         
  1649.         // get the FSSpec for the selected file
  1650.         if (theFSSpecPtr != NULL)
  1651.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1652.  
  1653.         NavDisposeReply(&myReply);
  1654.     }
  1655.         
  1656.     *theIsSelected = myReply.validRecord;
  1657.     if (myReply.validRecord)
  1658.         *theIsReplacing = myReply.replacing;
  1659.  
  1660.     DisposeNavEventUPP(myEventUPP);
  1661. #endif
  1662.  
  1663.     return(myErr);
  1664. }
  1665.     
  1666.  
  1667. //////////
  1668. //
  1669. // QTFrame_GetOneFileWithPreview
  1670. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  1671. // selects a file, return information about it using the theFSSpecPtr parameter.
  1672. //
  1673. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  1674. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  1675. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  1676. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  1677. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  1678. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  1679. // filter to return false if a file is to be displayed.
  1680. //
  1681. //////////
  1682.  
  1683. OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  1684. {
  1685. #if TARGET_OS_WIN32
  1686.     StandardFileReply    myReply;
  1687. #endif
  1688. #if TARGET_OS_MAC
  1689.     NavReplyRecord        myReply;
  1690.     NavDialogOptions    myDialogOptions;
  1691.     NavTypeListHandle    myOpenList = NULL;
  1692.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1693. #endif
  1694.     OSErr                myErr = noErr;
  1695.     
  1696.     if (theFSSpecPtr == NULL)
  1697.         return(paramErr);
  1698.     
  1699.     // deactivate any frontmost movie window
  1700.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1701.  
  1702. #if TARGET_OS_WIN32
  1703.     // prompt the user for a file
  1704.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  1705.     if (!myReply.sfGood)
  1706.         return(userCanceledErr);
  1707.     
  1708.     // make an FSSpec record
  1709.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  1710. #endif
  1711.  
  1712. #if TARGET_OS_MAC
  1713.     // specify the options for the dialog box
  1714.     NavGetDefaultDialogOptions(&myDialogOptions);
  1715.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  1716.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  1717.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1718.     
  1719.     // create a handle to an 'open' resource
  1720.     myOpenList = (NavTypeListHandle)QTFrame_CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  1721.     if (myOpenList != NULL)
  1722.         HLock((Handle)myOpenList);
  1723.     
  1724.     // prompt the user for a file
  1725.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  1726.     if ((myErr == noErr) && myReply.validRecord) {
  1727.         AEKeyword        myKeyword;
  1728.         DescType        myActualType;
  1729.         Size            myActualSize = 0;
  1730.         
  1731.         // get the FSSpec for the selected file
  1732.         if (theFSSpecPtr != NULL)
  1733.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1734.  
  1735.         NavDisposeReply(&myReply);
  1736.     }
  1737.     
  1738.     if (myOpenList != NULL) {
  1739.         HUnlock((Handle)myOpenList);
  1740.         DisposeHandle((Handle)myOpenList);
  1741.     }
  1742.     
  1743.     DisposeNavEventUPP(myEventUPP);
  1744. #endif
  1745.  
  1746.     return(myErr);
  1747. }
  1748.  
  1749.  
  1750. //////////
  1751. //
  1752. // QTFrame_HandleNavEvent
  1753. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  1754. //
  1755. //////////
  1756.  
  1757. PASCAL_RTN void QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  1758. {
  1759. #pragma unused(theCallBackUD)
  1760.     WindowReference        myWindow = NULL;    
  1761.     
  1762.     if (theCallBackSelector == kNavCBEvent) {
  1763.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  1764.             case updateEvt:
  1765. #if TARGET_OS_MAC
  1766.                 QTFrame_HandleEvent(theCallBackParms->eventData.eventDataParms.event);
  1767. #endif
  1768.                 break;
  1769.             case nullEvent:
  1770.                 QTFrame_IdleMovieWindows();
  1771.                 break;
  1772.         }
  1773.     }
  1774. }
  1775.  
  1776.  
  1777. //////////
  1778. //
  1779. // QTFrame_CreateOpenHandle
  1780. // Return a handle to a dynamically-created 'open' resource.
  1781. //
  1782. //////////
  1783.  
  1784. Handle QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList)
  1785. {
  1786.     Handle            myHandle = NULL;
  1787.     
  1788.     if (theTypeList == NULL)
  1789.         return(myHandle);
  1790.     
  1791.     if (theNumTypes > 0) {
  1792.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  1793.         if (myHandle != NULL) {
  1794.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  1795.             
  1796.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  1797.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  1798.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  1799.         }
  1800.     }
  1801.     
  1802.     return(myHandle);
  1803. }
  1804.  
  1805.  
  1806. //////////
  1807. //
  1808. // QTFrame_GetFileFilterUPP
  1809. // Return a UPP for the specified file-selection filter function.
  1810. //
  1811. // The caller is responsible for disposing of the UPP returned by this function (by calling DisposeRoutineDescriptor).
  1812. //
  1813. //////////
  1814.  
  1815. QTFrameFileFilterUPP QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc)
  1816. {
  1817. #if TARGET_OS_MAC
  1818.     return(NewNavObjectFilterUPP((NavObjectFilterProcPtr)theFileFilterProc));
  1819. #endif
  1820. #if TARGET_OS_WIN32
  1821.     return(NewFileFilterProc(theFileFilterProc));
  1822. #endif
  1823. }
  1824.  
  1825.  
  1826. //////////
  1827. //
  1828. // QTFrame_FilterFiles
  1829. // Filter files for a file-opening dialog box.
  1830. //
  1831. // The default behavior here is to accept all files that can be opened by QuickTime, whether directly
  1832. // or using a movie importer or a graphics importer.
  1833. //
  1834. //////////
  1835.  
  1836. #if TARGET_OS_MAC
  1837. PASCAL_RTN Boolean QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode)
  1838. {
  1839. #pragma unused(theCallBackUD, theFilterMode)
  1840.     NavFileOrFolderInfo        *myInfo = (NavFileOrFolderInfo *)theInfo;
  1841.     
  1842.     if (gValidFileTypes == NULL)
  1843.         QTFrame_BuildFileTypeList();
  1844.  
  1845.     if (theItem->descriptorType == typeFSS) {
  1846.         if (!myInfo->isFolder) {
  1847.             OSType            myType = myInfo->fileAndFolder.fileInfo.finderInfo.fdType;
  1848.             short            myCount;
  1849.             short            myIndex;
  1850.             
  1851.             // see whether the file type is in the list of file types that our application can open 
  1852.             myCount = GetPtrSize((Ptr)gValidFileTypes) / sizeof(OSType);
  1853.             for (myIndex = 0; myIndex < myCount; myIndex++)
  1854.                 if (myType == gValidFileTypes[myIndex])
  1855.                     return(true);
  1856.  
  1857.             // if we got to here, it's a file we cannot open
  1858.             return(false);        
  1859.         }
  1860.     }
  1861.     
  1862.     // if we got to here, it's a folder or non-HFS object
  1863.     return(true);
  1864. }
  1865. #endif
  1866. #if TARGET_OS_WIN32
  1867. PASCAL_RTN Boolean QTFrame_FilterFiles (CInfoPBPtr thePBPtr)
  1868. {
  1869. #pragma unused(thePBPtr)
  1870.     return(false);
  1871. }
  1872. #endif
  1873.  
  1874.  
  1875. //////////
  1876. //
  1877. // QTFrame_BuildFileTypeList
  1878. // Build a list of file types that QuickTime can open.
  1879. //
  1880. //////////
  1881.  
  1882. OSErr QTFrame_BuildFileTypeList (void)
  1883. {
  1884.     long        myIndex = 0;
  1885.     OSErr        myErr = noErr;
  1886.  
  1887.     // if we've already built the list, just return
  1888.     if (gValidFileTypes != NULL)
  1889.         return(myErr);
  1890.     
  1891.     // allocate a block of memory to hold a preset number of file types; we'll resize this block
  1892.     // while building the list if we need more room; we always resize it after building the list,
  1893.     // to truncate it to the exact size required
  1894.     gValidFileTypes = (OSType *)NewPtrClear(sizeof(OSType) * kDefaultFileTypeCount);
  1895.     if (gValidFileTypes == NULL)
  1896.         return(memFullErr);
  1897.     
  1898.     // we can open any files of type kQTFileTypeMovie
  1899.     gValidFileTypes[myIndex++] = kQTFileTypeMovie;
  1900.     
  1901.     // we can open any files for which QuickTime supplies a movie importer component
  1902.     QTFrame_AddComponentFileTypes(MovieImportType, &myIndex);
  1903.     
  1904.     // we can open any files for which QuickTime supplies a graphics importer component
  1905.     QTFrame_AddComponentFileTypes(GraphicsImporterComponentType, &myIndex);
  1906.  
  1907.     // resize the pointer to hold the exact number of valid file types
  1908.     SetPtrSize((Ptr)gValidFileTypes, myIndex * sizeof(OSType));
  1909.     myErr = MemError();
  1910.     
  1911.     return(myErr);
  1912. }
  1913.  
  1914.  
  1915. //////////
  1916. //
  1917. // QTFrame_AddComponentFileTypes
  1918. // Add all subtypes of the specified component type to the global list of file types.
  1919. //
  1920. //////////
  1921.  
  1922. static void QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex)
  1923. {
  1924.     ComponentDescription        myFindCompDesc = {0, 0, 0, 0, 0};
  1925.     ComponentDescription        myInfoCompDesc = {0, 0, 0, 0, 0};
  1926.     Component                    myComponent = NULL;
  1927.  
  1928.     myFindCompDesc.componentType = theComponentType;
  1929.     myFindCompDesc.componentFlags = 0;
  1930.     myFindCompDesc.componentFlagsMask = movieImportSubTypeIsFileExtension;
  1931.  
  1932.     myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1933.     while (myComponent != NULL) {
  1934.         GetComponentInfo(myComponent, &myInfoCompDesc, NULL, NULL, NULL);
  1935.         gValidFileTypes[*theNextIndex] = myInfoCompDesc.componentSubType;
  1936.         *theNextIndex += 1;
  1937.         
  1938.         // resize the block of file types, if we are about to reach the limit
  1939.         if (*theNextIndex == GetPtrSize((Ptr)gValidFileTypes) / (long)sizeof(OSType)) {
  1940.             SetPtrSize((Ptr)gValidFileTypes, GetPtrSize((Ptr)gValidFileTypes) + (kDefaultFileTypeCount * sizeof(OSType)));
  1941.             if (MemError() != noErr)
  1942.                 return;
  1943.         }
  1944.         
  1945.         myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1946.     }
  1947. }
  1948.  
  1949.  
  1950. #if TARGET_OS_WIN32
  1951. //////////
  1952. //
  1953. // QTFrame_ConvertMacToWinRect
  1954. // Convert a Macintosh Rect structure into a Windows RECT structure.
  1955. //
  1956. //////////
  1957.  
  1958. void QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect)
  1959. {
  1960.     theWinRect->top = (long)theMacRect->top;
  1961.     theWinRect->left = (long)theMacRect->left;
  1962.     theWinRect->bottom = (long)theMacRect->bottom;
  1963.     theWinRect->right = (long)theMacRect->right;
  1964. }
  1965.  
  1966.  
  1967. //////////
  1968. //
  1969. // QTFrame_ConvertWinToMacRect
  1970. // Convert a Windows RECT structure into a Macintosh Rect structure.
  1971. //
  1972. //////////
  1973.  
  1974. void QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect)
  1975. {
  1976.     theMacRect->top = (short)theWinRect->top;
  1977.     theMacRect->left = (short)theWinRect->left;
  1978.     theMacRect->bottom = (short)theWinRect->bottom;
  1979.     theMacRect->right = (short)theWinRect->right;
  1980. }
  1981. #endif
  1982.